package net.wangds.yunz.auth.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class AuthenicationsUtils {

    public static boolean hasPrivelege(String target, Collection<GrantedAuthority> auths){

        if(auths==null){
            return false;
        }

        for(GrantedAuthority auth:auths){
            String au = auth.getAuthority();
           if(StringUtils.equals(au, "ROLE_ADMIN")){
               //管理员角色返回所有功能.
               return true;
           }

           if(StringUtils.equals(au, target)){
             return true;
           }

        }

        return false;
    }

}
